package com.wing.product.service;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.common.utils.JsonResult;
import com.wing.product.dao.WarehouseProductMarkPriceDao;
import com.wing.product.model.entity.WarehouseProductMarkPrice;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WarehouseProductMarkPriceServiceImpl extends ServiceImpl<WarehouseProductMarkPriceDao, WarehouseProductMarkPrice> implements WarehouseProductMarkPriceService{
    @Override
    public Page<Map> pageList4app(Page page, Map<String, Object> params) {
        List<Map> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public JsonResult saveWarehouseProductMarkPrice(WarehouseProductMarkPrice warehouseProductMarkPrice) {
        if (ObjectUtil.isNotEmpty(warehouseProductMarkPrice)){
            this.baseMapper.insert(warehouseProductMarkPrice);
            return JsonResult.success("添加成功");
        }else {
            return JsonResult.fail("添加失败");
        }
    }

    @Override
    public Map computePriceDiameter(String type, String processId, String markId, String diameter) {
        List<Map> list=baseMapper.computePriceDiameter(type,processId,markId,diameter);
        Map map=new HashMap();
        if(list.size()>0){
           map.put("diameterPrice",list.get(0).get("unit_price"));
        }else{
            map.put("diameterPrice",0);
        }
        return map;
    }

    @Override
    public Map computePriceLength(String type, String processId, String markId, String warehouseLength) {
        List<Map> list=baseMapper.computePriceLength(type,processId,markId,warehouseLength);
        Map map=new HashMap();
        if(list.size()>0){
            map.put("lengthPrice",list.get(0).get("unit_price"));
        }else{
            map.put("lengthPrice",0);
        }
        return map;
    }

    @Override
    public Map findLabelName(String id) {
        return baseMapper.findLabelName(id);
    }

    @Override
    public Map findBundle(String type, String processId, String markId) {
        List<Map> list=baseMapper.findBundle(type,processId,markId);
        Map map=new HashMap();
        if(list.size()>0){
            map.put("unit_price",list.get(0).get("unit_price"));
            map.put("upperThreshold",list.get(0).get("upper_threshold"));
        }else{
            map.put("unit_price",-1);
        }
        return map;
    }

    @Override
    public Map findMark(String markId) {
        return baseMapper.findMark(markId);
    }
}
